import { Injectable, InjectByName, InjectFactory } from '../../decorators/inject';
import { NTableEvent } from '../../types/cors';
import { IValueString } from './types';
import { ITableDatas } from '../../cors/table-datas.interface';
import { TableFormula } from './table-formula';
import { ValueFormula } from './value-formula';
@Injectable()
export class ValueString implements IValueString {
  public type: 'value' = 'value';
  public dataType: 'string' = 'string';
  public displayValue: string|number|boolean = '';
  public value: string;
  constructor(
    @InjectByName('TableEvent') protected tableEvent: NTableEvent.IDataEvent,
    @InjectByName('TableDatas') protected tableDatas: ITableDatas,
    @InjectFactory() protected factory: (args: any) => any
  ) {
    // console.log(this)
    console.dir(ValueFormula)
  }
  public update(val: any) {
    // if(typeof val === 'string' && val[0] === '=') {
    //   let formula = this.factory(TableFormula) as TableFormula;
    //   let result = formula.updateFormulaStr(val.replace('=',''));
    //   console.log(result)
    // }
    this.value = val;
    this.displayValue = val;
  }
  public toString() {
    return this.value.toString();
  }
  public getOriginDataType() {
    return 'string';
  }
  public getValue() {
    return this.displayValue;
  }
  public destroy() {

  }
}